Skip to content

Conversation

@ohbarye
Copy link
Owner

@ohbarye ohbarye commented Jun 29, 2025

Summary

  • Fixed IntegerArbitrary#shrink to ensure all generated values stay within the specified min/max bounds
  • Added proper bound clamping for both target and intermediate shrink values
  • Updated tests to reflect the corrected behavior

Problem

The shrink method was generating values outside the specified range constraints. For example, with min: 25, max: 65, it could produce values like 0 or -1, which violate the minimum bound.

Solution

  • When no target is specified, the method now uses the closest value to 0 that's within bounds
  • All intermediate values during shrinking are clamped to stay within [min, max]
  • The target value is also clamped to ensure it's valid

Test plan

  • All existing tests pass
  • Added tests to verify shrink respects min/max constraints
  • Verified that shrinking from various starting points stays within bounds

Fixes #35

ohbarye added 2 commits June 29, 2025 17:22
…traints

This commit adds test cases that verify the shrink method respects the
min/max range constraints. Currently these tests fail because shrink
always converges to 0, ignoring the specified range boundaries.

Issue: #35
Fixed an issue where IntegerArbitrary#shrink could produce values
outside the specified min/max range constraints.

Changes:
- When target is not specified, use the closest value to 0 within bounds
- Always clamp target to be within the valid range
- Clamp intermediate values during shrinking to stay within bounds
- Don't yield target if it equals the current value

This ensures that for ranges like min:25, max:65, all shrunk
values are guaranteed to be within the specified bounds.

Fixes #13
Added entry for PR #36 that fixes the shrink method to respect
min/max bounds in all cases.
@ohbarye ohbarye merged commit 15a8d6f into main Jun 29, 2025
4 checks passed
@ohbarye ohbarye deleted the fix-13 branch June 29, 2025 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IntegerArbitrary#shrink doesn't account for min/max values

1 participant